document.addEventListener('DOMContentLoaded', () => {
    const userInfo = localStorage.getItem('userInfo');
    const userDiv = document.getElementById('user-info');

    if (userInfo) {
        const user = JSON.parse(userInfo);
        userDiv.innerHTML = `
            <span>用户名: ${user.account}</span>
            <button onclick="logout()">登出</button>
        `;
    } else {
        userDiv.innerHTML = `
            <button onclick="redirectTo('login.html')">登录</button>
            <button onclick="redirectTo('register.html')">注册</button>
        `;
    }
});

function redirectTo(page) {
    window.location.href = page;
}

function logout() {
    localStorage.removeItem('userInfo');
    window.location.href = 'blog_list.html'; // 返回主页或登录页
}
function redirectToDetail(id) {
    window.location.href = `blog_detail.html?id=${id}`;
}

